package com.maxd.respository.helpTask;

import com.maxd.model.HelpTask;
import com.maxd.model.HelpUserScore;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

public interface HelpUserScoreRepository extends Repository<HelpUserScore, Long> {

    @Query(value = "select * from help_user_score t where t.user_id=:userId",nativeQuery = true)
    HelpUserScore selectById( @Param("userId") Long userId);

    @Transactional
    @Modifying
    @Query(value = "update help_user_score set score=score+:score,add_score=add_score+:score where user_id=:userId",nativeQuery = true)
    Integer updateUserScoreAdd( @Param("userId") Long userId,@Param("score") Integer score);

    @Transactional
    @Modifying
    @Query(value = "update help_user_score set score=score-:score,reduce_score=reduce_score+:score where user_id=:userId",nativeQuery = true)
    Integer updateUserScoreSub( @Param("userId") Long userId,@Param("score") Integer score);

}
